use docx_rust::{
    document::{Paragraph, Table, TableCell, TableRow},
    formatting::{TableCellProperty, TableProperty, TableRowProperty},
    Docx, DocxFile, DocxResult,
};

fn main() -> DocxResult<()> {
    let mut docx = Docx::default();

    let tbl = Table::default()
        .property(TableProperty::default())
        .push_row(
            TableRow::default()
                .property(TableRowProperty::default())
                .push_cell(Paragraph::default().push_text("Hello 123"))
                .push_cell(Paragraph::default())
                .push_cell(
                    TableCell::paragraph(Paragraph::default())
                        .property(TableCellProperty::default()),
                ),
        );

    docx.document.push(tbl);

    docx.write_file("tmp/table.docx")?;

    let path = std::path::Path::new("tmp/table.docx");

    let book = DocxFile::from_file(path).unwrap();

    let docx = book.parse().unwrap();

    for body_content in docx.document.body.content {
        if let docx_rust::document::BodyContent::Table(table) = body_content {
            for row in table.rows {
                for cell in row.cells {
                    if let docx_rust::document::TableRowContent::TableCell(cell) = cell {
                        for table_cell_content in cell.content {
                            if let docx_rust::document::TableCellContent::Paragraph(paragraph) =
                                table_cell_content
                            {
                                println!("{:?}", paragraph.text());
                                // for paragraph_content in paragraph.content{
                                //     println!("{:?}", paragraph_content);
                                // }
                            }
                        }
                    }
                }
            }
        }
    }

    Ok(())
}
